#ifndef GAMEELEMENTTOOL_H
#define GAMEELEMENTTOOL_H

#include "tool.h"
#include "rendermanager.h"
#include "GameEngine.h"
#include "vlgameelementscontextwidget.h"

#define gameCtx VLGameElementsContextWidget::getInstance()

#define PT_OFFSET 0.01

class GameElementTool: virtual public Tool
{
    RenderManager* rend;
    GameEngine* gameEng;
    GameElement* currentElement;
    vector3<float> switchCursorPos;
    vector3<int> elementCursorPos;
    bool switchMode;

    void selectElementFromCoords(int x, int y);
    void addElementFromCoords(int x, int y);
    void removeElementFromCoords(int x, int y);
    GameElement* getElementFromMouseCoords(int x, int y);
    GameElementTool();

public:

    static GameElementTool* getInstance();
    string getType(){return "GETool";}

    template <typename T, GAME_ELEMENT_TYPE N>
    T* getCurrentElement(){
        if(currentElement && currentElement->getType()==N)
            return dynamic_cast<T*>(currentElement);
        else return 0;
    }

    GAME_ELEMENT_TYPE getCurrentType()
    {
        if(currentElement)
        return currentElement->getType();
        return NO_TYPE;
    }

    GameElement* getCurrentGenericElement(){return currentElement;}

    Result mouseMoveEvent(QMouseEvent *event);
    Result mousePressEvent(QMouseEvent *event);
    Result mouseReleaseEvent(QMouseEvent *event);
    Result keyPressEvent(QKeyEvent *event);
    Result keyReleaseEvent(QKeyEvent *event);
    void display();
};

#endif // GAMEELEMENTTOOL_H
